import {useEffect, useRef} from 'react'
import Swiper from 'swiper'


import styled from'styled-components'
import {getImageUrl} from '../../../utils/utils.js'
const SWiperBox = styled.div`
  .swiper-slide{
      //width: 544px;
      //height: 231px;
      //background: linear-gradient(143deg, rgba(var(--theme_color), 0.7) 15.01%, rgba(var(--theme_color)) 53.73%);
      //filter: drop-shadow(0 0 50px #00000033);
      //box-sizing: border-box;
      //border-radius: 8px;
      width: 544px;
      height: 231px;
      border-radius: 8px;
      position: relative;
      box-sizing: border-box;
  }
  
`
//热门文化名片
const CulturalCardsItemBox = styled.div`
    width: 544px;
    height: 231px;
    background: linear-gradient(143deg, rgba(${props => props.rgbcolor}, 0.7) 15.01%, rgb(${props => props.rgbcolor}) 53.73%);
    position: relative;
    box-sizing: border-box;
    border-radius: 8px;

    .views {
        position: absolute;
        top: 17px;
        right: 18px;
        color: #ffffff;
        font-size: 16px;
        font-weight: 400;
        line-height: 14px;
        width: 55px;
        height: 14px;
        display: flex;
        align-items: center;

        .see {
            width: 18px;
            height: 16px;
            margin-right: 6px;
        }
    }

    .mask {
        width: calc(100% - 4px);
        height: calc(100% - 4px);
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        box-sizing: border-box;
        z-index: 5;
    }

    .content {
        width: calc(100% - 4px);
        height: calc(100% - 4px);
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        box-sizing: border-box;
        z-index: 10;

        .press-box {
            margin-top: 16px;
            margin-left: 16px;
            display: flex;

            .cover {
                width: 106px;
                height: 106px;
                border-radius: 50%;
                display: block;
            }

            .info {
                margin-left: 23px;

                .title {
                    color: #1c1c1c;
                    width: fit-content;
                    max-width: 238px;
                    margin-top: 14px;
                    position: relative;
                    font-size: 22px;
                    font-weight: 700;
                    line-height: 22px;

                    &::after {
                        content: '';
                        width: 100%;
                        height: 4px;
                        position: absolute;
                        background: linear-gradient(270deg, #ffffff00 0%, rgba(${props => props.rgbcolor})  100%);
                        left: 0;
                        bottom: 0;
                        z-index: -1;
                    }
                }

                .slogan {
                    max-width: 374px;
                    width: fit-content;
                    color: #666666;
                    font-weight: 400;
                    margin-top: 16px;
                    font-size: 15px;
                    line-height: 22px;
                }
            }
        }

        .statistics {
            width: 524px;
            height: 88px;
            background: #FFF;
            margin: 9px auto 0 auto;
            box-sizing: border-box;
            padding: 14px 55px;
            display: grid;
            grid-template-columns: repeat(3, auto);
            justify-content: space-between;
            gap: 17px 0;

            .statistics-item {
                display: flex;
                align-items: center;
                height: 21px;
                //justify-content: center;

                .icon {
                    font-size: 21px;
                    margin-right: 5px;
                    color: rgb(${props => props.rgbcolor});
                }

                .number {
                    color: #666666;
                    font-size: 16px;
                    font-weight: 400;
                }
            }
        }
    }

`

export function CulturalCardsItem({detail}) {
  return (<>
    <CulturalCardsItemBox color={detail?.presses?.theme_color} rgbcolor={detail?.presses?.theme_color} className={'item hover-box'}>
      <img src={getImageUrl('card_mask.png')} alt="" className={'mask'}/>
      <div className={'views'}>
        <img src={getImageUrl('specialColumn/white-see.png')} alt="" className={'see'}/>
        {detail?.presses?.views}
      </div>
      <div className={'content'}>
        <div className={'press-box'}>
          <img src={detail?.presses?.logo_url} alt="" className={'cover'}/>
          <div className={'info'}>
            <div className={'title u-line-1 hover-text'}>{detail?.presses?.press_name}</div>
            <div className={'slogan u-line-2'}>{detail?.presses?.slogan}</div>
          </div>
        </div>
        <div className={'statistics'}>
          <div className={'statistics-item'}>
            <div className="icon iconfont icon-activity"></div>
            <div className="number">活动：{detail?.presses?.activity_count}</div>
          </div>
          <div className={'statistics-item'}>
            <div className="icon iconfont icon-article"></div>
            <div className="number">文章：{detail?.presses?.article_count}</div>
          </div>
          <div className={'statistics-item'}>
            <div className="icon iconfont icon-person"></div>
            <div className="number">大咖：{detail?.presses?.influential_person_count}</div>
          </div>
          <div className={'statistics-item'}>
            <div className="icon iconfont icon-newspaper"></div>
            <div className="number">报刊：{detail?.presses?.publication_type_count}</div>
          </div>
          <div className={'statistics-item'}>
            <div className="icon iconfont icon-fans"></div>
            <div className="number">粉丝：{detail?.presses?.fans_count}</div>
          </div>
          <div className={'statistics-item'}>
            <div className="icon iconfont icon-goods"></div>
            <div className="number">商品：{detail?.presses?.goods_count}</div>
          </div>
        </div>
      </div>
    </CulturalCardsItemBox>
  </>)
}
export function CardBanner({list}){
  let swiper = useRef()
  const loop = list.length > 2;
  useEffect(() => {
    swiper.current = new Swiper(".swiper-container-card", {
      loop, // 无缝
      autoplay: {
        delay: 2000, // 时间间隔
        disableOnInteraction: false
      },
      slidesPerView: 'auto',
      centeredSlides: loop  ,
      paginationClickable: true,
      spaceBetween: 20,
      // 窗口变化,重新init,针对F11全屏和放大缩小,必须加
      observer: true,
      observeParents: true,
    });
    return () => {
      // 清理Swiper实例
      if (swiper.current) {
        swiper.current?.destroy(true, true);
      }
    };
  }, [list])
  return (<SWiperBox>
    <div className={'swiper-container swiper-container-card'}>
      <div className="swiper-wrapper">
        {
          list.map((item,index) => {
            return <div className={'swiper-slide'} key={index}>
              <CulturalCardsItem detail={item}></CulturalCardsItem>
            </div>
          })
        }
      </div>
    </div>
  </SWiperBox>)
}